package com.bawei.culture.view

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.RoutePath
import com.bawei.common.base.BaseActivity
import com.bawei.culture.R
import com.bawei.culture.databinding.ActivityCultureBinding

@Route(path = RoutePath.PATH_CULTURE_PAGE)
class CultureActivity : BaseActivity<ActivityCultureBinding>() {

    @Autowired
    @JvmField
    var moduleType: String = "1"
    override fun getLayoutId(): Int = R.layout.activity_culture

    override fun initView() {
        //使用ARouter的依赖注入功能
        //内部采用反射技术，为当前被@Autowired注释过的变量赋值（从内存LruCache中获取变量值）
        ARouter.getInstance().inject(this)
        //返回按钮的点击事件
        mDataBinding.includePageTitle.ivBack.setOnClickListener {
            this@CultureActivity.finish()
        }
        //初始化模块Fragment页面
        initModuleFragment()

    }

    private fun initModuleFragment(){
        when(moduleType){
            "7" -> {
                mDataBinding.includePageTitle.tvTitle.text = "文化编辑"
                commitFragment(CultureEditFragment.newInstance(), moduleType)
            }
            "8" -> {
                mDataBinding.includePageTitle.tvTitle.text = "发布公告"
                commitFragment(SendNoticeFragment.newInstance(), moduleType)
            }
            "9" -> {
                mDataBinding.includePageTitle.tvTitle.text = "文化管理"
                commitFragment(CultureManagerFragment.newInstance(), moduleType)
            }
            "10" -> {
                mDataBinding.includePageTitle.tvTitle.text = "公告管理"
                commitFragment(NoticeManagerFragment.newInstance(), moduleType)
            }
        }
    }

    /**
     * 通过事务提交Fragment
     */
    private fun commitFragment(moduleFragment: Fragment, fragmentTag: String){
        //1.获取fragmentManager对象
        var fm = supportFragmentManager
        //2.开始事务
        var fragmentTransaction = fm.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container, moduleFragment, fragmentTag)
        fragmentTransaction.commit()
    }


}